//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hualude.roadsign.utils;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.shade.com.alibaba.fastjson.JSONArray;
import com.lab205.send.dto.*;

import java.util.Properties;

public class KeKeSender {
    private static Properties properties = new Properties();
    private static Producer producer = null;

    static {
        properties.put("ProducerId", "PID_main_mq");
        properties.put("AccessKey", "9e4DvabTkrpciMCY");
        properties.put("SecretKey", "NQeb1IAfkHiehPCPgKe12LoxAwWUoV");
        properties.put("ONSAddr", "http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet?spm=5176.2020520107.0.0.b2lEzo");
    }

    public synchronized static void init() {
        producer = ONSFactory.createProducer(properties);
        producer.start();
    }

    public synchronized static void sendSMSInfo(String sourceAddr, String destAddr, String smsFreeSignName, String smsTemplateCode, String smsParam) {
        if (producer == null) {
            init();
        }
        MessageDTO msgDto = new MessageDTO(sourceAddr, destAddr, "SMS", new SMSDTO(smsFreeSignName, smsParam, smsTemplateCode));
        JSONArray json = new JSONArray();
        json.add(msgDto);
        Message msg = new Message("main_message_queue", "SMS", json.toJSONString().getBytes());
        System.out.println(json.toJSONString());
        msg.setKey("ORDERID_100");
        producer.send(msg);

    }

    public static void sendEMailInfo(String sourceAddr, String destAddr, String subject, String nickName, String mailParam, String template) {
        if (producer == null) {
            init();
        }
        MessageDTO msgDto = new MessageDTO(sourceAddr, destAddr, "EMAIL", new MailDTO(subject, mailParam, nickName, template));
        JSONArray json = new JSONArray();
        json.add(msgDto);
        Message msg = new Message("main_message_queue", "EMAIL", json.toJSONString().getBytes());
        msg.setKey("ORDERID_100");
        producer.send(msg);

    }

    public static void sendAndroidPushMessageInfo(String sourceAddr, String destAddr, String pushContent, String pushTarget, String pushTitle) {
        if (producer == null) {
            init();
        }
        MessageDTO msgDto = new MessageDTO(sourceAddr, destAddr, "PUSH_ANDROID_MESSAGE", new PushMessageDTO(pushTarget, pushTitle, pushContent));
        JSONArray json = new JSONArray();
        json.add(msgDto);
        Message msg = new Message("main_message_queue", "PUSH_ANDROID_MESSAGE", json.toJSONString().getBytes());
        msg.setKey("ORDERID_100");
        producer.send(msg);

    }

    public static void sendAndroidPushNoticeInfo(String sourceAddr, String destAddr, String pushContent, String pushTarget, String pushTitle, String extParameters) {
        if (producer == null) {
            init();
        }
        MessageDTO msgDto = new MessageDTO(sourceAddr, destAddr, "PUSH_ANDROID_NOTICE", new AndroidPushNoticeDTO(pushTarget, pushTitle, pushContent, extParameters));
        JSONArray json = new JSONArray();
        json.add(msgDto);
        Message msg = new Message("main_message_queue", "PUSH_ANDROID_NOTICE", json.toJSONString().getBytes());
        msg.setKey("ORDERID_100");
        producer.send(msg);

    }

    public static void sendIOSPushMessageInfo(String sourceAddr, String destAddr, String pushContent, String pushTarget, String pushTitle) {
        if (producer == null) {
            init();
        }
        MessageDTO msgDto = new MessageDTO(sourceAddr, destAddr, "PUSH_IOS_MESSAGE", new PushMessageDTO(pushTarget, pushTitle, pushContent));
        JSONArray json = new JSONArray();
        json.add(msgDto);
        Message msg = new Message("main_message_queue", "PUSH_IOS_MESSAGE", json.toJSONString().getBytes());
        msg.setKey("ORDERID_100");
        producer.send(msg);
    }

    public static void sendIOSPushNoticeInfo(String sourceAddr, String destAddr, String pushContent, String pushTarget, String pushTitle, String extParameters, String apnsEnv) {
        if (producer == null) {
            init();
        }
        MessageDTO msgDto = new MessageDTO(sourceAddr, destAddr, "PUSH_IOS_NOTICE", new IOSPushNoticeDTO(pushTarget, pushTitle, pushContent, extParameters, apnsEnv));
        JSONArray json = new JSONArray();
        json.add(msgDto);
        Message msg = new Message("main_message_queue", "PUSH_IOS_NOTICE", json.toJSONString().getBytes());
        msg.setKey("ORDERID_100");
        producer.send(msg);
    }
}
